package com.example.apiproject.controller;

import com.example.apiproject.entity.Labels;
import com.example.apiproject.service.LabelsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Labels)表控制层
 *
 * @author makejava
 * @since 2023-09-23 13:40:57
 */
@RestController
@RequestMapping("labels")
public class LabelsController {
    /**
     * 服务对象
     */
    @Resource
    private LabelsService labelsService;

    /**
     * 分页查询
     *
     * @param labels 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Labels>> queryByPage(Labels labels, PageRequest pageRequest) {
        return ResponseEntity.ok(this.labelsService.queryByPage(labels, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param user_id 主键
     * @return 单条数据
     */
    @GetMapping("{user_id}")
    public ResponseEntity<Labels> queryById(@PathVariable("user_id") Integer user_id) {
        return ResponseEntity.ok(this.labelsService.queryById(user_id));
    }

    /**
     * 新增数据
     *
     * @param labels 实体
     * @return 新增结果
     */
//    @PostMapping
//    public ResponseEntity<Labels> add(@RequestBody Labels labels) {
//        return ResponseEntity.ok(this.labelsService.insert(labels));
//    }

    /**
     * 编辑数据
     *
     * @param labels 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Labels> edit(Labels labels) {
        return ResponseEntity.ok(this.labelsService.update(labels));
    }

    /**
     * 删除数据w
     *
     * @param user_id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer user_id) {
        return ResponseEntity.ok(this.labelsService.deleteById(user_id));
    }

}

